package com.service.lotterySystem.bean;

import com.service.lotterySystem.service.ActivityService;
import com.service.lotterySystem.util.ApplicationContextUtils;
import org.quartz.*;
import org.springframework.scheduling.quartz.QuartzJobBean;

/**
 * @author ：hjl
 * @date ：Created in 2022/01/14 10:54
 * @description：
 */
public class EndActivityTaskBean extends QuartzJobBean  {
    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
        String activityId = jobDataMap.getString("activityId");
        String taskName = jobDataMap.getString("taskName");
        String groupName = jobDataMap.getString("groupName");

        ActivityService activityService = (ActivityService) ApplicationContextUtils.getBean("activityServiceImpl");
        activityService.endActivity(activityId);

        JobKey jobKey=new JobKey(taskName,groupName);
        try {
            context.getScheduler().deleteJob(jobKey);
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
}
